<?php
class Morderindetail extends CI_Model {
    protected $_table;
    public function __construct() {
        parent::__construct();
        $this->_table="order_in_detail";
    }
    
    public function listAll($oi_id) {
        $query=$this->db->query("SELECT o . * , p.pro_title
                                FROM order_in_detail AS o
                                INNER JOIN products AS p ON p.pro_id = o.pro_id
                                where o.oi_id = $oi_id");
        if($query->num_rows()>0) return $query->result_array(); else return false;
    }
    
    public function countAll() {
        return $this->db->count_all($this->_table);
    }
    
    public function getById($id) {
        $query=$this->db->query("SELECT o . * , p.pro_title
                                FROM order_in_detail AS o
                                INNER JOIN products AS p ON p.pro_id = o.pro_id
                                where o.oid_id = $id");
        if($query->num_rows()>0) return $query->row_array(); else return false;
    }
    
    public function insert($data) {
        $this->db->insert($this->_table, $data);
    }
    
    public function update($data, $id) {
        $this->db->where("oid_id", $id);
        $this->db->update($this->_table, $data);
    }
    
    public function del($id) {
        $this->db->where("oid_id", $id);
        $this->db->delete($this->_table);
    }
}
?>
